//获取ID
function autohidetimes(){
	var s = document.getElementById("autohide");
	if(s.innerHTML == 0){
		return false;
	}else{
		setTimeout("autohidetimes()",1000);
	}
	s.innerHTML = s.innerHTML * 1 - 1;
	return true;
}
function $id(id){
    return document.getElementById(id);
    }
function ShowMsg(){
    document.writeln("<div id=\"msgdiv\" style=\"position:absolute;display:none;border:2px solid #D0D0D0;\"><\/div>");
    document.writeln("<div id=\"overdiv\" style=\"position:absolute;display:none;\">");
    document.writeln("<\/div>");
    //回调函数
    this.ok_callback=function(){};
    this.cancel_callback=function(){};
	this.hide_callback=function(){};
    this.msgobjname=""
    this.show=function(msgtitle,msgcontent,selecttype,url1,url2,hidetime,autoturn){
        var tempobj1=$id("msgdiv");
        var tempobj2=$id("overdiv");
        var msgobj=this.msgobjname;
          tempobj2.style.filter="alpha(opacity=10)";
          tempobj2.style.MozOpacity = 10/100;
        tempobj2.style.backgroundColor = "#000000";
         tempobj2.style.display = '';
        tempobj2.style.zIndex= 100;
        tempobj2.style.height= document.documentElement.clientHeight+"px";
        tempobj2.style.width= document.documentElement.clientWidth+"px";
            tempobj2.style.left=0;
            tempobj2.style.top=0;
            tempobj1.style.display="none";
        tempobj1.style.left= (document.documentElement.clientWidth-245)/2+"px";
        tempobj1.style.top= (document.documentElement.scrollTop+(document.documentElement.clientHeight)/4-50)+"px";
        tempobj1.style.display= '';
        tempobj1.style.width=245+"px";
        tempobj1.style.height=230+"px";
        tempobj1.style.zIndex= 200;
        tempobj1.style.backgroundColor = "#F6F6F6";
        var OutStr;

		OutStr='<div style="width:245px;height:26px;background-color:#DFDFDF;" ><div  style="font-weight:bolder;text-align:center;float:left;padding-top:3px;width:205px;height:26px;font-size:14px;cursor:move" canmove="true" forid="msgdiv" >'+msgtitle+'</div><div style="text-align:center;float:right;padding-top:5px;width:30px;font-size:12px;cursor:hand" onclick="'+msgobj+'.hide(\''+url1+'\')">关闭</div></div>'
        OutStr=OutStr+"<div style=\"height:150px;width:160px;word-wrap:break-word;margin-left:auto;margin-right:auto; font-size:12px;\"><br>"+msgcontent+"</div>"
        if(selecttype==2){
            OutStr=OutStr+"<div style=\"text-align:center;font-size:12px;height:35px;\"><input type=\"button\" value=\"确定\" onclick=\""+msgobj+".ok('"+url1+"')\">    <input type=\"button\" value=\"取消\" onclick=\""+msgobj+".cancel('"+url2+"')\"></div>"
        }
        else if(selecttype==1){
            OutStr=OutStr+"<div style=\"text-align:center;font-size:12px;height:35px;\"><input type=\"button\" value=\"确定\" onclick=\""+msgobj+".ok('"+url1+"')\"></div>"
        }
		if(hidetime>0){
			OutStr=OutStr+"<div style=\"text-align:center;font-size:12px;\"><span id=\"autohide\">"+hidetime+"</span>秒后"+autoturn+"</div>"
			setTimeout("autohidetimes()",1000);
			var hidetime1000=hidetime*1000;
			setTimeout(msgobj+'.hide("'+url1+'")',hidetime1000); //10秒后定时关闭  
		}
        tempobj1.innerHTML=OutStr;
        var md=false,mobj,ox,oy
        document.onmousedown=function(ev)
        {
            var ev=ev||window.event;
            var evt=ev.srcElement||ev.target;
            if(typeof(evt.getAttribute("canmove"))=="undefined")
            {
                 return;
            }
            if(evt.getAttribute("canmove"))
            {
                md = true;
                mobj = document.getElementById(evt.getAttribute("forid"));
                ox = mobj.offsetLeft - ev.clientX;
                oy = mobj.offsetTop - ev.clientY;
            }
        }
        document.onmouseup= function(){md=false;}
        document.onmousemove= function(ev)
        {
            var ev=ev||window.event;
            if(md)
            {
                mobj.style.left= (ev.clientX + ox)+"px";
                mobj.style.top= (ev.clientY + oy)+"px";
            }
        }
        }
        this.ok = function(url)
        {
            $id('msgdiv').style.display='none';
            $id('overdiv').style.display='none';
            this.ok_callback(url);
        }
        this.cancel=function(url){
            $id('msgdiv').style.display='none';
            $id('overdiv').style.display='none';
            this.cancel_callback(url);
        }

		this.hide=function(url){			
            $id('msgdiv').style.display='none';
            $id('overdiv').style.display='none';
			if(url=="back")
			{
				history.back();
			}else if(url!=""){
				location=url;
			}
        }
    }

var MessageBox=new ShowMsg();
//设置对象名,供内部引用
MessageBox.msgobjname="MessageBox";
//定义回调函数
MessageBox.ok_callback=function(url){
	if(url=="back")
	{
		history.back();
	}else if(url!=""){
		location=url;
	}
	return 1;
}
MessageBox.cancel_callback=function(url){
	if(url=="back")
	{
		history.back();
	}else if(url!=""){
		location=url;
	}
	return 0;
}